<template>
  <div>
    <div>
      <h3 id="title">绑定银行卡</h3>
    </div>
    <Back></Back>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  label-width="100px" class="demo-ruleForm">
      <el-form-item label="银行卡号" prop="card_num">
        <el-input v-model="ruleForm.card_num"></el-input>
      </el-form-item>
      <el-form-item label="银行类型" prop="bank_type">
        <el-input v-model="ruleForm.bank_type"></el-input>
      </el-form-item>
      <el-form-item label="电话号码" prop="phone">
        <el-input v-model="ruleForm.phone"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">绑定</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import back from '@/components/back/Return';
import { addCard } from '@/api/info';
export default {
  name: "card",
  data() {
    return {
      ruleForm: {
        card_num: '',
        bank_type:'',
        phone: ''
      },
      rules: {
        card_num: [
          { required: true, message: '请输入银行卡号', trigger: 'blur' },
          { min: 15, max: 19, message: '长度为15-19位', trigger: 'blur' }
        ],
        bank_type: [
          { required: true, message: '请输入银行类型', trigger: 'blur' }
        ],
        phone: [
          { type: 'date', required: true, message: '请输入电话号码', trigger: 'blur' },
          { min: 11,max: 11, message: '至少1元', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    //添加卡号
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
          //发送请求
          addCard(this.ruleForm).then(respone=>{
            console.log(respone);
          }).catch(error=>{
            console.log(error);
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  components: {
    'Back': back
  }
}
</script>

<style scoped>
#title{
  line-height: 100px;
  text-align: center;
  color: #00a854;
}
</style>